<?
$txtten=replatestring($_POST[txtten],false);
$alias= make_title_furl($_POST["txtten"]);
$txtcode=replatestring($_POST[txtcode],false);
if($txtcode==""){$txtcode=0;}
$txtnoidung=replatesnoidung($_POST[txtnoidung]);
$txttomtat=replatestring($_POST[txttomtat],false);
$txtlogo=replatestring($_POST[userfile],false);
$txtstatus=replatestring($_POST[txtstatus],false);
$id=replatestring($_POST[id],false);
$parent=replatestring($_POST['parent'],false);
$txtgia=replatestring($_POST['txtgia'],false);
$slsao=replatestring($_POST['slsao'],false);
if($parent>0)
{
	///////////////////////////////////////////
	$caseid= findcase($parent,"loaitin_id",$label);
	$casealias= findcase($parent,"loaitin_alias",$label);
	$casetieude= findcase($parent,"loaitin_tieude",$label);
	///////////////////////////////////////////
}

$loai=replatestring($_POST[loai],false);
$vitri=replatestring($_POST[slvitri],false);
$txttitle=$_POST[txttitle];if($txttitle==""){$txttitle=$txtten;}
$txtkeyword=$_POST[txtkeyword];if($txtkeyword==""){$txtkeyword=$txtten;}
$txtdesciption=$_POST[txtdesciption];if($txtdesciption==""){$txtdesciption=$txtten;}
$txtthutu=$_POST[txtthutu];
if($loai==""){$loai=replatestring($_GET[loai],false);}
if($loai==""){$loai=0;}
if($parent==""){$parent=0;}
//Kiem tra tính hợp lệ của dữ liệu
$data=false;
$links="index.php?progid=6&loai=$loai";
if($txtvitri==1){$links.="&home=1";}
if(checkstring($txtstatus,"number",2)==true){$data=true;}
if($data==true){
	if($id==""){
		
		//mysql_query("call sp_tbtintuc_them('$parent','$txtten','$txttomtat','$txtnoidung','$txtlogo','$txtvitri','$txtstatus','$loai','$txtcode')");
		//mysql_query("SET character_set_client=utf8", $links);
		//mysql_query("SET character_set_connection=utf8", $links);

		mysql_query("insert into tbtintuc (loaitin_id,tintuc_tieude,tintuc_alias,tintuc_tomtat,tintuc_noidung,tintuc_title,tintuc_keyword,tintuc_des, tintuc_hinhanh,tintuc_vitri,tintuc_thutu, tintuc_trangthai,tintuc_phanloai,tintuc_caseid,tintuc_casealias,tintuc_casetieude, lang_id) value ('$parent','$txtten','$alias','$txttomtat','$txtnoidung','$txttitle','$txtkeyword','$txtdesciption','$txtlogo','$vitri','$txtthutu','$txtstatus','$loai','$caseid' ,'$casealias' ,'$casetieude','$lang')");
		//include 'send.php';
		$cauthongbao="Bạn đã thêm thành công";
		$link=$links;
		thongbao($cauthongbao,$link);
	}else{
	//Sủa tài khỏan
		
		//mysql_query("call sp_tbtintuc_sua('$parent','$txtten','$txttomtat','$txtnoidung','$txtlogo','$txtvitri','$txtstatus','$loai','$txtcode','$id')");
		//mysql_query("SET character_set_client=utf8", $links);
		//mysql_query("SET character_set_connection=utf8", $links);
		mysql_query("Update tbtintuc SET loaitin_id='$parent',tintuc_tieude='$txtten',tintuc_alias='$alias',tintuc_tomtat='$txttomtat',tintuc_noidung='$txtnoidung',tintuc_title='$txttitle',tintuc_keyword='$txtkeyword',tintuc_des='$txtdesciption', tintuc_hinhanh='$txtlogo',tintuc_vitri='$vitri',tintuc_thutu='$txtthutu', tintuc_trangthai='$txtstatus' , tintuc_caseid='$caseid' , tintuc_casealias='$casealias' , tintuc_casetieude='$casetieude' where tintuc_id='$id'");
		//include 'send.php';
		$cauthongbao="Bạn đã sửa thành công";
		$link=$links;
		thongbao($cauthongbao,$link);
	}
}else{
		$cauthongbao="Dữ liệu không hợp lệ";
		$link="index.php?progid=6&loai=$loai";
		thongbao($cauthongbao,$link);
}

?>